package com.example.hello.model;

import lombok.*;
import org.hibernate.annotations.Type;
import org.joda.money.Money;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
//1处理数据库
@Entity
//2关联表和实体类
@Table(name = "t_drink")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Drink {
    //3主键映射，关联
    @Id
    //规则
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id; //    商品编号

//    @Column(name = "name")
    @NotBlank
    public String name; //   名称


    //4外键一列
    @Column
    //5Money自己实现转换
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    @NotNull
    public Money price; //  价格

    @ManyToOne
    public Category category;
}
